<<usegrids>>
<div id="emailstabs">
<ul>
<<section name="emailstab" loop="$emailstabtypes">>
    <li><a href="#emailstabs-<<$smarty.section.emailstab.iteration>>"><<$emailstabtypes[emailstab].title>></a></li>
<</section>>
</ul>
<<section name="tab" loop="$emailstabtypes">>
    <div id="emailstabs-<<$smarty.section.tab.iteration>>">
<<$emailstabtypes[tab].content>>
    </div>
<</section>>
</div>

<button onclick="saveemails()">Save emails</button>

<script>
function saveemails() {
    callAdminService("emails", "savecontent", {
        register_validation         : jQuery("textarea[name='register_validation']").html(),
        register_validation_subject : jQuery("input[name='register_validation_subject']").val(),
        register_finished           : jQuery("textarea[name='register_finished']").html(),
        register_finished_subject   : jQuery("input[name='register_finished_subject']").val(),
        sendorder                   : jQuery("textarea[name='sendorder']").html(),
        sendorder_subject           : jQuery("input[name='sendorder_subject']").val(),
        sponsor_reminder            : jQuery("textarea[name='sponsor_reminder']").html(),
        sponsor_reminder_subject    : jQuery("input[name='sponsor_reminder_subject']").val(),
        profile_update              : jQuery("textarea[name='profile_update']").html(),
        profile_update_subject      : jQuery("input[name='profile_update_subject']").val(),
        bl_update                   : jQuery("textarea[name='bl_update']").html(),
        bl_update_subject           : jQuery("input[name='bl_update_subject']").val(),
        forgottenpassword           : jQuery("textarea[name='forgottenpassword']").html(),
        forgottenpassword_subject   : jQuery("input[name='forgottenpassword_subject']").val(),
        usercreated                 : jQuery("textarea[name='usercreated']").html(),
        usercreated_subject         : jQuery("input[name='usercreated_subject']").val(),
        invoice                     : jQuery("textarea[name='invoice']").html(),
        invoice_subject             : jQuery("input[name='invoice_subject']").val(),
        ad_expire                   : jQuery("textarea[name='ad_expire']").html(),
        ad_expire_subject           : jQuery("input[name='ad_expire_subject']").val()
    }, {
        success : function(result) {
            displayMessage("info", "Automated emails have been successfully saved!");
        }
    });
}

jQuery("div#emailstabs").tabs({
    select: function(event, ui) {
        switch (ui.index) {
<<section name="tab" loop="$emailstabtypes">>
            case <<$smarty.section.tab.iteration-1>>: {
                if (typeof(window["on<<$emailstabtypes[tab].type>>Open"]) == "function") {
                    on<<$emailstabtypes[tab].type>>Open();
                }
            }
<</section>>
        }
    }
});
if (typeof(window["on<<$emailstabtypes[0].type>>Open"]) == "function") {
    on<<$emailstabtypes[0].type>>Open();
}

createEditors();

function sendTest(emailname) {
    callAdminService("emails", "sendtestemail", {
        email : jQuery("input[name='emailaddress_" + emailname + "']").val(),
        emailname : emailname
    }, {
        success : function() {
            displayMessage("info", "Test email sent to the desired email address!");
        }
    });
}

</script>
